<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Scala | whoway</title>
    <meta name="description" content="Personal Blog Website">
    <link rel="icon" href="/images/photo.jpg">
  <link rel="manifest" href="/images/photo.jpg">
  <link rel="apple-touch-icon" href="/images/photo.jpg">
  <meta http-quiv="pragma" cotent="no-cache">
  <meta http-quiv="pragma" cotent="no-cache,must-revalidate">
  <meta http-quiv="expires" cotent="0">
    
    <link rel="preload" href="/assets/css/0.styles.0dbae9ec.css" as="style"><link rel="preload" href="/assets/js/app.c70e21ad.js" as="script"><link rel="preload" href="/assets/js/47.67116354.js" as="script"><link rel="prefetch" href="/assets/js/10.15222a53.js"><link rel="prefetch" href="/assets/js/100.7e0e5a86.js"><link rel="prefetch" href="/assets/js/101.efd59f25.js"><link rel="prefetch" href="/assets/js/102.dfbdc06c.js"><link rel="prefetch" href="/assets/js/103.d3ab2109.js"><link rel="prefetch" href="/assets/js/104.117957ef.js"><link rel="prefetch" href="/assets/js/105.046e8ff3.js"><link rel="prefetch" href="/assets/js/106.aebdc17d.js"><link rel="prefetch" href="/assets/js/107.248733c2.js"><link rel="prefetch" href="/assets/js/108.a2fecadc.js"><link rel="prefetch" href="/assets/js/109.35196857.js"><link rel="prefetch" href="/assets/js/11.770642f2.js"><link rel="prefetch" href="/assets/js/110.cf3d973c.js"><link rel="prefetch" href="/assets/js/111.f985889a.js"><link rel="prefetch" href="/assets/js/112.ad614f41.js"><link rel="prefetch" href="/assets/js/113.f666653c.js"><link rel="prefetch" href="/assets/js/114.c6c3f384.js"><link rel="prefetch" href="/assets/js/115.e51d3c2f.js"><link rel="prefetch" href="/assets/js/116.4f4b39f5.js"><link rel="prefetch" href="/assets/js/117.99352e11.js"><link rel="prefetch" href="/assets/js/118.c6ae6572.js"><link rel="prefetch" href="/assets/js/119.4ccbe778.js"><link rel="prefetch" href="/assets/js/12.042a92ff.js"><link rel="prefetch" href="/assets/js/120.edda1c4f.js"><link rel="prefetch" href="/assets/js/121.30a638ed.js"><link rel="prefetch" href="/assets/js/122.6efcefb1.js"><link rel="prefetch" href="/assets/js/123.91e6665b.js"><link rel="prefetch" href="/assets/js/124.f27e3d7e.js"><link rel="prefetch" href="/assets/js/125.c75712d5.js"><link rel="prefetch" href="/assets/js/126.ed756cce.js"><link rel="prefetch" href="/assets/js/127.2f06c74c.js"><link rel="prefetch" href="/assets/js/128.d5f6f30e.js"><link rel="prefetch" href="/assets/js/129.508b7eed.js"><link rel="prefetch" href="/assets/js/13.b5280c37.js"><link rel="prefetch" href="/assets/js/130.dc05f9aa.js"><link rel="prefetch" href="/assets/js/131.e0ba69b1.js"><link rel="prefetch" href="/assets/js/132.d79bcaa4.js"><link rel="prefetch" href="/assets/js/133.34acc01a.js"><link rel="prefetch" href="/assets/js/134.dabf64d5.js"><link rel="prefetch" href="/assets/js/135.ad90c915.js"><link rel="prefetch" href="/assets/js/136.dbb0074f.js"><link rel="prefetch" href="/assets/js/137.284ad365.js"><link rel="prefetch" href="/assets/js/138.a4b6856f.js"><link rel="prefetch" href="/assets/js/139.c9c1e20f.js"><link rel="prefetch" href="/assets/js/14.df02ba38.js"><link rel="prefetch" href="/assets/js/140.8b0a9269.js"><link rel="prefetch" href="/assets/js/141.9c7759c5.js"><link rel="prefetch" href="/assets/js/142.a4201a82.js"><link rel="prefetch" href="/assets/js/143.d7da6e8c.js"><link rel="prefetch" href="/assets/js/144.5e48e65d.js"><link rel="prefetch" href="/assets/js/145.a0e2633c.js"><link rel="prefetch" href="/assets/js/146.3c775f9b.js"><link rel="prefetch" href="/assets/js/147.22add89a.js"><link rel="prefetch" href="/assets/js/148.cfde1009.js"><link rel="prefetch" href="/assets/js/149.ffc835b5.js"><link rel="prefetch" href="/assets/js/15.fbdfc4ee.js"><link rel="prefetch" href="/assets/js/150.406c4b20.js"><link rel="prefetch" href="/assets/js/151.b2040eea.js"><link rel="prefetch" href="/assets/js/152.7bc65661.js"><link rel="prefetch" href="/assets/js/153.1d7c65e3.js"><link rel="prefetch" href="/assets/js/154.1309de49.js"><link rel="prefetch" href="/assets/js/155.81d3ee1f.js"><link rel="prefetch" href="/assets/js/156.154a4ef2.js"><link rel="prefetch" href="/assets/js/16.e5eb6147.js"><link rel="prefetch" href="/assets/js/17.57853c4a.js"><link rel="prefetch" href="/assets/js/18.cb9d7518.js"><link rel="prefetch" href="/assets/js/19.f354dc47.js"><link rel="prefetch" href="/assets/js/2.570d8a23.js"><link rel="prefetch" href="/assets/js/20.b5af7fad.js"><link rel="prefetch" href="/assets/js/21.0b1928fe.js"><link rel="prefetch" href="/assets/js/22.f78666de.js"><link rel="prefetch" href="/assets/js/23.29c3f366.js"><link rel="prefetch" href="/assets/js/24.6f596516.js"><link rel="prefetch" href="/assets/js/25.14067b60.js"><link rel="prefetch" href="/assets/js/26.74ba4989.js"><link rel="prefetch" href="/assets/js/27.13d60edd.js"><link rel="prefetch" href="/assets/js/28.9523cb32.js"><link rel="prefetch" href="/assets/js/29.8ec842e9.js"><link rel="prefetch" href="/assets/js/3.3fb3d2e0.js"><link rel="prefetch" href="/assets/js/30.805597a8.js"><link rel="prefetch" href="/assets/js/31.831b195d.js"><link rel="prefetch" href="/assets/js/32.063c672d.js"><link rel="prefetch" href="/assets/js/33.6d93fac3.js"><link rel="prefetch" href="/assets/js/34.56e8263c.js"><link rel="prefetch" href="/assets/js/35.dbe688bb.js"><link rel="prefetch" href="/assets/js/36.dc5af2c1.js"><link rel="prefetch" href="/assets/js/37.0a7494f6.js"><link rel="prefetch" href="/assets/js/38.fe4fc171.js"><link rel="prefetch" href="/assets/js/39.f5ed5e92.js"><link rel="prefetch" href="/assets/js/4.2c405ec8.js"><link rel="prefetch" href="/assets/js/40.fe7e2714.js"><link rel="prefetch" href="/assets/js/41.30b0811d.js"><link rel="prefetch" href="/assets/js/42.76f52d62.js"><link rel="prefetch" href="/assets/js/43.e7bb0817.js"><link rel="prefetch" href="/assets/js/44.ead0e883.js"><link rel="prefetch" href="/assets/js/45.235df046.js"><link rel="prefetch" href="/assets/js/46.5f09e829.js"><link rel="prefetch" href="/assets/js/48.31f34543.js"><link rel="prefetch" href="/assets/js/49.10b5ebba.js"><link rel="prefetch" href="/assets/js/5.6f47322c.js"><link rel="prefetch" href="/assets/js/50.c0f0b7f1.js"><link rel="prefetch" href="/assets/js/51.5143f3bf.js"><link rel="prefetch" href="/assets/js/52.eeddfd48.js"><link rel="prefetch" href="/assets/js/53.eb790db5.js"><link rel="prefetch" href="/assets/js/54.8fe5421c.js"><link rel="prefetch" href="/assets/js/55.d8f9004b.js"><link rel="prefetch" href="/assets/js/56.62ac9b92.js"><link rel="prefetch" href="/assets/js/57.a9caec0d.js"><link rel="prefetch" href="/assets/js/58.f93fc522.js"><link rel="prefetch" href="/assets/js/59.a81a03aa.js"><link rel="prefetch" href="/assets/js/6.8c2ea393.js"><link rel="prefetch" href="/assets/js/60.ab782775.js"><link rel="prefetch" href="/assets/js/61.6dd12daf.js"><link rel="prefetch" href="/assets/js/62.76f4b01f.js"><link rel="prefetch" href="/assets/js/63.6f8a4742.js"><link rel="prefetch" href="/assets/js/64.6f8bb1fa.js"><link rel="prefetch" href="/assets/js/65.4120a44b.js"><link rel="prefetch" href="/assets/js/66.360c2d2b.js"><link rel="prefetch" href="/assets/js/67.26f84d32.js"><link rel="prefetch" href="/assets/js/68.68f45e5e.js"><link rel="prefetch" href="/assets/js/69.e311eb56.js"><link rel="prefetch" href="/assets/js/7.6762b2d7.js"><link rel="prefetch" href="/assets/js/70.cea82674.js"><link rel="prefetch" href="/assets/js/71.783ddcf7.js"><link rel="prefetch" href="/assets/js/72.e5467385.js"><link rel="prefetch" href="/assets/js/73.b8fb681b.js"><link rel="prefetch" href="/assets/js/74.1bae37db.js"><link rel="prefetch" href="/assets/js/75.024387e5.js"><link rel="prefetch" href="/assets/js/76.a8e53010.js"><link rel="prefetch" href="/assets/js/77.8c55500a.js"><link rel="prefetch" href="/assets/js/78.7ce90bf5.js"><link rel="prefetch" href="/assets/js/79.ef71713f.js"><link rel="prefetch" href="/assets/js/8.788a6364.js"><link rel="prefetch" href="/assets/js/80.acad589d.js"><link rel="prefetch" href="/assets/js/81.02670d10.js"><link rel="prefetch" href="/assets/js/82.53b7b1ac.js"><link rel="prefetch" href="/assets/js/83.99eb8581.js"><link rel="prefetch" href="/assets/js/84.d1535ce3.js"><link rel="prefetch" href="/assets/js/85.fe2b7de9.js"><link rel="prefetch" href="/assets/js/86.41850272.js"><link rel="prefetch" href="/assets/js/87.1cdc6df9.js"><link rel="prefetch" href="/assets/js/88.01bf3461.js"><link rel="prefetch" href="/assets/js/89.17c69819.js"><link rel="prefetch" href="/assets/js/9.3813842d.js"><link rel="prefetch" href="/assets/js/90.f6ae7e35.js"><link rel="prefetch" href="/assets/js/91.507bc284.js"><link rel="prefetch" href="/assets/js/92.90551782.js"><link rel="prefetch" href="/assets/js/93.dc442d78.js"><link rel="prefetch" href="/assets/js/94.315f4e94.js"><link rel="prefetch" href="/assets/js/95.ccd6c6bf.js"><link rel="prefetch" href="/assets/js/96.0c6d89d0.js"><link rel="prefetch" href="/assets/js/97.1a9f10a9.js"><link rel="prefetch" href="/assets/js/98.43be3caa.js"><link rel="prefetch" href="/assets/js/99.54c8207b.js">
    <link rel="stylesheet" href="/assets/css/0.styles.0dbae9ec.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">whoway</span></a> <div class="links" style="max-width:nullpx;"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">🎓Coding</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/00.Coding/TheBeautyOfProgramming/" class="nav-link">🔖编程之美题解</a></li><li class="dropdown-item"><!----> <a href="/00.Coding/CodeWarehouse/" class="nav-link">🔖代码意识流</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">🚀语言</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/01.Language/Overview/" class="nav-link">🔖概述</a></li><li class="dropdown-item"><!----> <a href="/01.Language/C/" class="nav-link">⭐️C</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Cpp/" class="nav-link">🚀C++</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Java/" class="nav-link">☕️Java</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Python/" class="nav-link">🧩Python3</a></li></ul></div></div><div class="nav-item"><a href="/02.Hardware/" class="nav-link">✔️硬件基础</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">⭐️软件基础</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/03.Software/01.DataStructureAndAlgorithm/" class="nav-link">🐾数据结构和算法</a></li><li class="dropdown-item"><!----> <a href="/03.Software/02.OS/" class="nav-link">💻操作系统</a></li><li class="dropdown-item"><!----> <a href="/03.Software/03.Net/" class="nav-link">☁️计算机网络</a></li><li class="dropdown-item"><!----> <a href="/03.Software/04.SE/" class="nav-link">✅软件工程</a></li></ul></div></div><div class="nav-item"><a href="/04.Database/" class="nav-link">🎨数据库</a></div><div class="nav-item"><a href="/05.Engineer/" class="nav-link">🔖学术/工程</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">⚙️工具</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/06.Tools/01.employment/" class="nav-link">🔖求职</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/02.efficiency/" class="nav-link">🚀效能</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/03.windows/" class="nav-link">⚙️Windows</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/04.design/" class="nav-link">🧩设计</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/05.linux/" class="nav-link">🐉Linux</a></li></ul></div></div><div class="nav-item"><a href="https://github.com/whoway" target="_blank" rel="noopener noreferrer" class="nav-link external">
  GitHub
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar"><nav class="nav-links"><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">🎓Coding</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/00.Coding/TheBeautyOfProgramming/" class="nav-link">🔖编程之美题解</a></li><li class="dropdown-item"><!----> <a href="/00.Coding/CodeWarehouse/" class="nav-link">🔖代码意识流</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">🚀语言</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/01.Language/Overview/" class="nav-link">🔖概述</a></li><li class="dropdown-item"><!----> <a href="/01.Language/C/" class="nav-link">⭐️C</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Cpp/" class="nav-link">🚀C++</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Java/" class="nav-link">☕️Java</a></li><li class="dropdown-item"><!----> <a href="/01.Language/Python/" class="nav-link">🧩Python3</a></li></ul></div></div><div class="nav-item"><a href="/02.Hardware/" class="nav-link">✔️硬件基础</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">⭐️软件基础</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/03.Software/01.DataStructureAndAlgorithm/" class="nav-link">🐾数据结构和算法</a></li><li class="dropdown-item"><!----> <a href="/03.Software/02.OS/" class="nav-link">💻操作系统</a></li><li class="dropdown-item"><!----> <a href="/03.Software/03.Net/" class="nav-link">☁️计算机网络</a></li><li class="dropdown-item"><!----> <a href="/03.Software/04.SE/" class="nav-link">✅软件工程</a></li></ul></div></div><div class="nav-item"><a href="/04.Database/" class="nav-link">🎨数据库</a></div><div class="nav-item"><a href="/05.Engineer/" class="nav-link">🔖学术/工程</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">⚙️工具</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/06.Tools/01.employment/" class="nav-link">🔖求职</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/02.efficiency/" class="nav-link">🚀效能</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/03.windows/" class="nav-link">⚙️Windows</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/04.design/" class="nav-link">🧩设计</a></li><li class="dropdown-item"><!----> <a href="/06.Tools/05.linux/" class="nav-link">🐉Linux</a></li></ul></div></div><div class="nav-item"><a href="https://github.com/whoway" target="_blank" rel="noopener noreferrer" class="nav-link external">
  GitHub
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <!----></nav>  <ul class="sidebar-links"><li><div class="sidebar-group first"><p class="sidebar-heading open"><span>Scala</span> <!----></p> <ul class="sidebar-group-items"><li><a href="/01.Language/Scala/01.Scala%E6%95%99%E7%A8%8B.html#目录" class="sidebar-link">目录</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/01.Language/Scala/01.Scala%E6%95%99%E7%A8%8B.html#scala编程-译者序" class="sidebar-link">Scala编程-译者序</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/01.Language/Scala/01.Scala%E6%95%99%E7%A8%8B.html#序" class="sidebar-link">序</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/01.Language/Scala/01.Scala%E6%95%99%E7%A8%8B.html#_01-scala『历史』和『设计思想』" class="sidebar-link">01.Scala『历史』和『设计思想』</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/01.Language/Scala/01.Scala%E6%95%99%E7%A8%8B.html#_1-1-范式" class="sidebar-link">1.1.范式</a></li><li class="sidebar-sub-header"><a href="/01.Language/Scala/01.Scala%E6%95%99%E7%A8%8B.html#_1-2-数据类型大小写之类的" class="sidebar-link">1.2.数据类型大小写之类的</a></li><li class="sidebar-sub-header"><a href="/01.Language/Scala/01.Scala%E6%95%99%E7%A8%8B.html#_1-3-语法对比『难点』" class="sidebar-link">1.3.语法对比『难点』</a></li><li class="sidebar-sub-header"><a href="/01.Language/Scala/01.Scala%E6%95%99%E7%A8%8B.html#_1-4-思想对比" class="sidebar-link">1.4.思想对比</a></li><li class="sidebar-sub-header"><a href="/01.Language/Scala/01.Scala%E6%95%99%E7%A8%8B.html#_1-5-支持编程方式" class="sidebar-link">1.5.支持编程方式</a></li></ul></li><li><a href="/01.Language/Scala/01.Scala%E6%95%99%E7%A8%8B.html#_02-配置环境" class="sidebar-link">02.配置环境</a><ul class="sidebar-sub-headers"></ul></li><li><a href="/01.Language/Scala/01.Scala%E6%95%99%E7%A8%8B.html#_03-观察现象" class="sidebar-link">03.观察现象</a><ul class="sidebar-sub-headers"></ul></li></ul></div></li></ul> </div> <div class="page"> <div class="content"><h1 id="scala"><a href="#scala" class="header-anchor">#</a> Scala</h1> <ul><li>来自C++栈的学习者</li> <li>基于CentOS Linux搭建环境学习</li></ul> <h2 id="目录"><a href="#目录" class="header-anchor">#</a> 目录</h2> <h2 id="scala编程-译者序"><a href="#scala编程-译者序" class="header-anchor">#</a> Scala编程-译者序</h2> <ul><li>相信大多数商业软件的程序员都是从Fortran、Pascal、C/C++/Java或COBOL语言一路学起的。本书中，这一大类的语言被称为是<strong>指令式语言</strong>，意指以变量和过程语句构造指令的方式对需要实现的目的进行编码的语言。与之相对的是被称为函数式语言的另一个大类，这种语言把程序的目的转换为函数和函数应用，是以函数计算这种不同的视角来处理一般问题的。</li> <li>直到现在，Lisp、Scheme或者Haskell 这样的函数式语言也仅仅还是“小众”语言。这在TIOBE语言排行榜上也可见一斑。上榜的前20 位几乎被面向对象的或者面向过程的指令式语言占满。尤其是前三甲则几乎始终被Java、C、和C++所把持。反观函数式语言，Lisp在第13位，是最靠前的了，Scheme在第25位，Haskell在第40位左右。但并不是说函数式语言对于指令式语言就不具有可比性,相反，在很多地方函数式语言都体现了它们独到的优势，如:代码的简洁性、值的不可改变、函数的无副作用、值和函数替换的指称透明等。</li> <li>但函数式语言与指令式语言总显得有点儿“格格不入”。一-个被指令式语言锻炼出来的头脑很难理解函数式语言的精髓，已经用惯了循环语句的方式解决问题，想要把它转换为递归语句也不是很容易的事情。莫非，函数式语言始终只能作为学术派的思维游戏，而不能适应于现代商业软件开发的需要，因此无缘商业软件开发浪潮的洗礼吗?</li> <li>所以说，Scala语言的确具有很新颖的创意。因为它能很巧妙地把指令式语言与函数式语言结合在一起。用Martin Odersky 的话说，就是:指令式语言与函数式语言本就是一枚硬币的两面，它们不应是互相排斥、非此即彼的，而是可以互相协调，共同发挥出更大力量的。</li></ul> <h2 id="序"><a href="#序" class="header-anchor">#</a> 序</h2> <ul><li>Martin Odersky设计的Pizza语言曾经震惊了Java世界。尽管Pizza语言本身并不流行，但它巧妙地把面向对象和函数型语言两种风格融合在了一起，形成了自然而又强有力的组合。Pizza 语言的设计成为了Java泛型的基础，Martin的GJ ( Generic Java)编译器从Java 1.3开始成为了Sun公司的标准编译器（尽管关闭了泛型)。我有幸维护这个编译器多年，因此对Martin设计与实现语言的能力有非常直接的体会。</li> <li>近年来，静态类型语言受到了冲击。<strong>Java的广泛应用暴露了静态语言编程会导致大量固定写法的弊病</strong>。常见的看法是我们应避免静态类型从而消除这种代码，于是人们对动态语言如 Python，Ruby 和Groovy的兴趣开始增加。这种看法被Martin最近的构想，Scala的出现打破。</li> <li>Scala是一种类型优雅的语言:<strong>它是静态类型的，但仅在需要的地方显式定义类型</strong>。Scala 从面向对象和函数式语言两方面获得了强大的特性，然后用全新的理念把它们完美地整合成一体。它的语法是如此的轻量级，而原语（primitive )又如此富有表达力，以至于根本可以认为API的使用不会产生语法开销。我们可以在标准库中，如拆分器、组合器和执行器中发现例子。而这也说明Scala是支持内嵌的特定领域语言。</li> <li>Scala会成为下一个伟大的语言吗?只有时间可以证明一切。我相信 Martin Odersky 的小组绝对有这样的能力和水平做到这-一-点。不过有一件事是确定无疑的:Scala语言建立了衡量未来语言的新标准。</li></ul> <h2 id="_01-scala『历史』和『设计思想』"><a href="#_01-scala『历史』和『设计思想』" class="header-anchor">#</a> 01.Scala『历史』和『设计思想』</h2> <h3 id="_1-1-范式"><a href="#_1-1-范式" class="header-anchor">#</a> 1.1.范式</h3> <div class="language-cpp line-numbers-mode"><pre class="language-cpp"><code>C<span class="token operator">++</span>是多范式编程语言成功的典范。
    C<span class="token operator">++</span>支持和C语言一样的过程式编程范式，
    也支持面向对象编程范式，
    支持泛型编程能力。
    支持多种范式可能是C<span class="token operator">++</span>直到现在仍然具有强大的生命力的原因之一。
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><ul><li>Scala是一种多范式的编程语言</li> <li>Scala是一门多范式的编程语言，一种类似Java 的编程语言，设计初衷是要集成『面向对象编程』和『函数式编程』的各种特性。</li> <li>我们认为最有意义的学习方式是，不要把Scala看做是改进的Java，而是把它作为一门新的语言。所以这里不会介绍Java的使用经验，而将集中讲解解释器和“对象-函数式”的风格，以及 Scala编程风格。特别强调了可维护性，并发，常用工具和利用类型系统的优势。</li></ul> <h3 id="_1-2-数据类型大小写之类的"><a href="#_1-2-数据类型大小写之类的" class="header-anchor">#</a> 1.2.数据类型大小写之类的</h3> <ul><li>C++中都是小写</li> <li>Java中除了int之类『<strong>基本数据类型</strong>』的用小写，泛型编程的都用大写开头『和C++不同』</li></ul> <h3 id="_1-3-语法对比『难点』"><a href="#_1-3-语法对比『难点』" class="header-anchor">#</a> 1.3.语法对比『难点』</h3> <ul><li>Scala 与 Java 的最大区别是：Scala 语句末尾的分号 <code>;</code> 是可选的</li> <li>Scala大小写敏感，可以接受。C++和Java也是。。。</li></ul> <p>1、<strong>类名</strong> - 对于所有的类名的『<strong>第一个字母要大写</strong>』。
如果需要使用几个单词来构成一个类的名称，每个单词的第一个字母要大写。
示例：<em>class <strong>M</strong>yFirstScalaClass</em></p> <p>2、<strong>方法名称</strong> - 所有的方法名称的『<strong>第一个字母用小写</strong>』。
如果若干单词被用于构成方法的名称，则每个单词的第一个字母应大写。
示例：<em>def <strong>m</strong>yMethodName()</em></p> <p>3、<strong>程序文件名</strong> - 程序文件的名称应该与对象名称完全匹配(<strong>新版本不需要了</strong>，但建议保留这种习惯)。『<strong>好家伙，Java的这种弊病也给学习到了</strong>。。。』
保存文件时，应该保存它使用的对象名称（记住Scala是区分大小写），并追加&quot;.scala&quot;为文件扩展名。 （如果文件名和对象名称不匹配，程序将无法编译）。</p> <p>示例: 假设&quot;HelloWorld&quot;是对象的名称。那么该文件应保存为'HelloWorld.scala&quot;</p> <div class="language-scala line-numbers-mode"><pre class="language-scala"><code><span class="token keyword">def</span> main<span class="token punctuation">(</span>args<span class="token operator">:</span> Array<span class="token punctuation">[</span><span class="token builtin">String</span><span class="token punctuation">]</span><span class="token punctuation">)</span> 
<span class="token comment">//Scala程序从main()方法开始处理，</span>
<span class="token comment">//这是每一个Scala程序的强制程序入口部分。</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><ul><li>类似C++中的</li></ul> <h3 id="_1-4-思想对比"><a href="#_1-4-思想对比" class="header-anchor">#</a> 1.4.思想对比</h3> <ul><li>可以认为 Scala 程序是对象的集合，通过调用彼此的方法来实现消息传递</li> <li><strong>字段 -</strong> 每个对象都有它唯一的『<strong>实例变量</strong>』集合，即字段。对象的属性通过给字段赋值来创建。『好家伙，又创建新概念。。。没事干嘛。。不就是变量嘛。。。』</li></ul> <h3 id="_1-5-支持编程方式"><a href="#_1-5-支持编程方式" class="header-anchor">#</a> 1.5.支持编程方式</h3> <ul><li>1、交互式编程，交互式编程不需要创建脚本文件，『类似、Matlab、Python，好家伙』</li> <li>2、脚本形式『好家伙，原来我写的代码是脚本？？我还以为是纯编译的。。。』</li></ul> <h2 id="_02-配置环境"><a href="#_02-配置环境" class="header-anchor">#</a> 02.配置环境</h2> <ul><li>Scala是基于java之上，大量使用java的类库和变量，使用 Scala 之前必须先安装 <strong>Java（&gt;1.5版本）</strong></li></ul> <div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">[</span>root@CentosLinux MyScala<span class="token punctuation">]</span><span class="token comment"># javac -version</span>
javac <span class="token number">1.8</span>.0_275
<span class="token punctuation">[</span>root@CentosLinux MyScala<span class="token punctuation">]</span><span class="token comment"># java -version</span>
openjdk version <span class="token string">&quot;1.8.0_275&quot;</span>
OpenJDK Runtime Environment <span class="token punctuation">(</span>build <span class="token number">1.8</span>.0_275-b01<span class="token punctuation">)</span>
OpenJDK <span class="token number">64</span>-Bit Server VM <span class="token punctuation">(</span>build <span class="token number">25.275</span>-b01, mixed mode<span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">[</span>root@CentosLinux ~<span class="token punctuation">]</span><span class="token comment"># wget https://downloads.lightbend.com/scala/2.13.5/scala-2.13.5.rpm</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">[</span>root@CentosLinux ~<span class="token punctuation">]</span><span class="token comment"># ls</span>
MyJava  MyScala  scala-2.13.5.rpm
<span class="token punctuation">[</span>root@CentosLinux ~<span class="token punctuation">]</span><span class="token comment"># mv scala-2.13.5.rpm /usr/share/</span>
<span class="token punctuation">[</span>root@CentosLinux ~<span class="token punctuation">]</span><span class="token comment"># vim /etc/profile</span>
<span class="token punctuation">[</span>root@CentosLinux ~<span class="token punctuation">]</span><span class="token comment"># scala</span>
-bash: scala: <span class="token builtin class-name">command</span> not found
<span class="token punctuation">[</span>root@CentosLinux ~<span class="token punctuation">]</span><span class="token comment"># cd /usr/share/</span>
<span class="token punctuation">[</span>root@CentosLinux share<span class="token punctuation">]</span><span class="token comment"># rpm -i scala-2.13.5.rpm</span>
<span class="token punctuation">[</span>root@CentosLinux share<span class="token punctuation">]</span><span class="token comment"># scala</span>
Welcome to Scala <span class="token number">2.13</span>.5 <span class="token punctuation">(</span>OpenJDK <span class="token number">64</span>-Bit Server VM, Java <span class="token number">1.8</span>.0_275<span class="token punctuation">)</span>.
Type <span class="token keyword">in</span> expressions <span class="token keyword">for</span> evaluation. Or try :help.

scala<span class="token operator">&gt;</span> q
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><h2 id="_03-观察现象"><a href="#_03-观察现象" class="header-anchor">#</a> 03.观察现象</h2> <div class="language-scala line-numbers-mode"><pre class="language-scala"><code><span class="token keyword">object</span> HelloWorld <span class="token punctuation">{</span>
  <span class="token keyword">def</span> main<span class="token punctuation">(</span>args<span class="token operator">:</span> Array<span class="token punctuation">[</span><span class="token builtin">String</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">Unit</span> <span class="token operator">=</span> <span class="token punctuation">{</span>
    println<span class="token punctuation">(</span><span class="token string">&quot;Hello, world!&quot;</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><div class="language-bash line-numbers-mode"><pre class="language-bash"><code><span class="token punctuation">[</span>root@CentosLinux MyScala<span class="token punctuation">]</span><span class="token comment"># scalac demo.scala</span>



<span class="token punctuation">[</span>root@CentosLinux MyScala<span class="token punctuation">]</span><span class="token comment"># ll</span>
total <span class="token number">12</span>
-rw-r--r-- <span class="token number">1</span> root root  <span class="token number">97</span> Apr <span class="token number">10</span> <span class="token number">10</span>:29 demo.scala
-rw-r--r-- <span class="token number">1</span> root root <span class="token number">639</span> Apr <span class="token number">10</span> <span class="token number">10</span>:30 HelloWorld.class
-rw-r--r-- <span class="token number">1</span> root root <span class="token number">677</span> Apr <span class="token number">10</span> <span class="token number">10</span>:30 HelloWorld$.class



<span class="token punctuation">[</span>root@CentosLinux MyScala<span class="token punctuation">]</span><span class="token comment"># scala HelloWorld</span>
Hello, world<span class="token operator">!</span>


<span class="token punctuation">[</span>root@CentosLinux MyScala<span class="token punctuation">]</span><span class="token comment"># java HelloWorld</span>
Exception <span class="token keyword">in</span> thread <span class="token string">&quot;main&quot;</span> java.lang.NoClassDefFoundError: scala/Predef$
        at HelloWorld$.main<span class="token punctuation">(</span>demo.scala:3<span class="token punctuation">)</span>
        at HelloWorld.main<span class="token punctuation">(</span>demo.scala<span class="token punctuation">)</span>
Caused by: java.lang.ClassNotFoundException: scala.Predef$
        at java.net.URLClassLoader.findClass<span class="token punctuation">(</span>URLClassLoader.java:382<span class="token punctuation">)</span>
        at java.lang.ClassLoader.loadClass<span class="token punctuation">(</span>ClassLoader.java:418<span class="token punctuation">)</span>
        at sun.misc.Launcher<span class="token variable">$AppClassLoader</span>.loadClass<span class="token punctuation">(</span>Launcher.java:352<span class="token punctuation">)</span>
        at java.lang.ClassLoader.loadClass<span class="token punctuation">(</span>ClassLoader.java:351<span class="token punctuation">)</span>
        <span class="token punctuation">..</span>. <span class="token number">2</span> <span class="token function">more</span>

</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br></div></div><ul><li>观察到竟然生成了2个文件？？尝试了</li> <li>Scala编译器将您的Scala代码编译为Java字节代码，然后可以通过' <strong>scala</strong> '命令执行。 ' <strong>scala</strong> '命令类似于<strong>java</strong>命令，因为它执行编译的Scala代码。</li></ul></div> <div class="page-edit"><!----> <!----></div> <!----> </div> <!----></div></div>
    <script src="/assets/js/app.c70e21ad.js" defer></script><script src="/assets/js/47.67116354.js" defer></script>
  </body>
</html>
